import { Controller, Get, Inject, Query } from '@nestjs/common';
import { Aaa9Service } from './aaa9.service';
import * as Minio from 'minio';
import { MINIO_CLIENT } from '../minio/minio.module';

@Controller('aaa9')
export class Aaa9Controller {
  constructor(private readonly aaa9Service: Aaa9Service) {}
  @Inject(MINIO_CLIENT)
  private minioClient: Minio.Client;
  
  @Get('test')
  async test() {
    try {
      await this.minioClient.fPutObject('aaa', 'hello.json', './package.json');
      return 'http://localhost:9000/aaa/hello.json';
    } catch(e) {
      console.log(e);
      return '上传失败';
    }
  }

  @Get('presignedUrl')
  async presignedUrl(@Query('name') name: string) {
    return this.minioClient.presignedPutObject('aaa', name, 3600)
  }
}
